package org.dawning.shop.category.entity;

import lombok.Data;
import org.dawning.shop.core.base.repository.RepositoryEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by L on 2017/6/13.
 * 基础分类
 */
@Data
public class BaseCategory extends RepositoryEntity {

    /**
     * 分类名
     */
    private String categoryName;

    /**
     * 分类CODE
     */
    private String categoryCode;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 对应的属性类型
     */
    private List<Type> typeList;

    /**
     * 父分类
     */
    private String parentId;

    /**
     * 祖先分类
     */
    private List<String> ancestorIds;

    /**
     * 添加类型
     * @param type
     */
    public void addType(Type type){
        if (this.typeList==null){
            this.typeList = new ArrayList<>();
        }
        this.typeList.add(type);
    }

    /**
     * 添加类型
     * @param typeList
     */
    public void addTypes(List<Type> typeList){
        if (typeList==null)return;
        if (this.typeList==null){
            this.typeList = new ArrayList<>();
        }
        this.typeList.addAll(typeList);
    }


    /**
     * 添加祖先id
     * @param pid
     */
    public void addAncestorId(String pid){
        if (this.ancestorIds==null){
            this.ancestorIds = new ArrayList<>();
        }
        this.ancestorIds.add(pid);
    }

    /**
     * 添加祖先id
     * @param pids
     */
    public void addAncestorIds(List<String> pids){
        if (pids==null)return;
        if (this.ancestorIds==null){
            this.ancestorIds = new ArrayList<>();
        }
        this.ancestorIds.addAll(pids);
    }
}

